package com.frostmourne.mxsattributeinventory.modules.extra;

import com.gitee.mxstars.mxscript.MXScriptExtra;
import org.apache.commons.lang3.tuple.MutablePair;
import org.apache.commons.lang3.tuple.Pair;
import org.bukkit.command.CommandSender;
import org.bukkit.event.inventory.InventoryClickEvent;

import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;

public class CancelEvent extends MXScriptExtra {
    @Override
    public Map<String, Pair<Class<?>, Method>> extraScript() {
        Class<?> scriptClass = CancelEvent.class;
        Map<String, Pair<Class<?>,Method>> scriptList = new HashMap<>();
        Method method;
        try {
            method = scriptClass.getDeclaredMethod("cancelEvent",CommandSender.class,String.class,InventoryClickEvent.class);
        } catch (NoSuchMethodException e) {
            throw new RuntimeException(e);
        }
        Pair<Class<?>,Method> pair = new MutablePair<>(scriptClass,method);
        scriptList.put("CANCEL-EVENT",pair);


        return scriptList;
    }

    public static void cancelEvent(CommandSender sender,String b,InventoryClickEvent event){
        event.setCancelled(Boolean.parseBoolean(b));
    }
}
